﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MusicService
{
    public partial class MusicService:ISongService
    {
        public bool addSong(string songName, string lyris)
        {
            bool flag = false;
            Song song = new Song();
            try
            {
                long numberSong = dc.Songs.Count() + 1;
                song.SongID = "SONG"+numberSong;
                song.SongName = songName;
                song.Lyrics = lyris;
                dc.Songs.InsertOnSubmit(song);
                dc.SubmitChanges();
                flag = true;
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public bool removeSong(string songID)
        {
            bool flag = false;
            try
            {
                Song song = dc.Songs.Single(s => s.SongID.Equals(songID));
                if (song != null)
                {
                    dc.Songs.DeleteOnSubmit(song);
                    dc.SubmitChanges();
                    flag = true;
                }
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public bool updateSong(string songID, string songName, string lyris)
        {
            bool flag = false;
            try
            {
                Song song = dc.Songs.Single(s => s.SongID.Equals(songID));
                if (song != null)
                {
                    song.SongName = songName;
                    song.Lyrics = lyris;
                    dc.SubmitChanges();
                    flag = true;
                }
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public List<Song> getAllSong()
        {
            var list = from s in dc.Songs select s;
            return list.ToList();
        }

        public Song getSongByName(string songName)
        {
            Song song = dc.Songs.Single(s => s.SongName.Equals(songName));
            return song;
        }
    }
}